<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
<script language="javascript" src="<?=public_js_path()?>jquery.js"></script>
<script type="text/javascript"> 
$(document).ready(function() {
	$("input").not("#submit_button").blur( function () {
		eval("chk_"+this.id+"()");
	});
	$("#submit_button").click( function () {
		var username_tag = $("#username_tag").html();
		var password_tag = $("#password_tag").html();
		var confirm_pwd_tag = $("#confirm_pwd_tag").html();
		var email_tag = $("#email_tag").html();
		var code_tag = $("#code_tag").html();
		var server = $("#server").attr("checked");
		if( server==false ){
			alert("同意服务条款才可注册");
		}
		if( username_tag=="" && password_tag=="" && confirm_pwd_tag=="" && email_tag==""){
			var username = $("#regist_username").val();
			var password = $("#regist_password").val();
			var email = $("#regist_email").val();
			var confirm_pwd = $("#regist_confirm_pwd").val();
			var code = $("#regist_code").val();
			regiest(username,password,confirm_pwd,email,code);
			return false;
		}else{
			return false;
		}
	});
});
/**
* 验证
*/
function chk_regist_username()
{
    var username = $("#regist_username").val();
	username = $.trim(username);
	if(username==""){
		$("#username_tag").html("用户名不能为空！");
		return false;
	}else{
		/*if ( username.search(/^[a-zA-Z0-9]{4,20}$/) == -1 ){
			$("#username_tag").html("用户名必须为4-20位英文或者数字！");
			return false;
		}*/
		$.ajax({
		   type: "POST",
		   url: "<?=site_url(array('home','regist'));?>",
		   data: "ck=username&username="+username,
		   success: function(msg){
		   		msg = jQuery.parseJSON(msg);
				if( msg.status==1 ){
					$("#username_tag").html("");
				}else{
					$("#username_tag").html(msg.info);
				}
		   }
		});
		var username_tag = $("#username_tag").html();
		if( username_tag=="" ){
			return true;
		}else{
			return false;
		}
	}
}
function chk_regist_password()
{
	var pwd = $("#regist_password").val();
	if(pwd==""){
		$("#password_tag").html("密码不能为空！");
		return false;
	}else {
		if ( pwd.search(/^[a-zA-Z0-9]{4,20}$/) == -1 ){
			$("#password_tag").html("密码必须为4-20位英文或者数字！");
			return false;
		}
		$("#password_tag").html("");
		return true;
	}
}
function chk_regist_confirm_pwd()
{
	var pwd = $("#regist_password").val();
	var confirm_pwd = $("#regist_confirm_pwd").val();
	if(confirm_pwd==""){
		$("#confirm_pwd_tag").html("确认密码不能为空！");
		return false;
	}
	if(pwd!=confirm_pwd){
		$("#confirm_pwd_tag").html("两次密码不一致！");
		return false;
	}
	$("#confirm_pwd_tag").html("");
	return true;
}
function chk_regist_email()
{
	var email = $("#regist_email").val();
	email = $.trim(email);
	if(email==""){
		$("#email_tag").html("邮箱不能为空！");
		return false;
	}else{
		$.ajax({
		   type: "POST",
		   url: "<?=site_url(array('home','regist'));?>",
		   data: "ck=email&email="+email,
		   success: function(msg){
		   		msg = jQuery.parseJSON(msg);
				if( msg.status==1 ){
					$("#email_tag").html("");
				}else{
					$("#email_tag").html(msg.info);
				}
		   }
		});
		var email_tag = $("#email_tag").html();
		if( email_tag=="" ){
			return true;
		}else{
			return false;
		}
	}
}	
function chk_server(){
	return true;
}
function regiest(username,password,confirm_pwd,email,code){
	$.ajax({
		type: "POST",
		url: "<?=site_url(array('home','regist'));?>",
		data: "username="+username+"&password="+password+"&confirm_pwd="+confirm_pwd+"&email="+email+"&code="+code,
		success: function(str){
			str = jQuery.parseJSON(str);
			if( str.status==1 ){
				$("#regist_info").html(str.info);
				return false;
			}else{
				alert(str.info);
				return false;
			}
		}
	});
}
</script>
</head>
<?php
echo "快来注册吧，赢取{$regist_coin}积分！";
?>
<body>
    <div>
    <div class="wrap">
        <div style="float:left;">
        </div>
        <div style="overflow:hidden;">
            <div>
            <div><div style=" border-bottom:2px #E68922 solid; font-size:14px; font-weight:bold; color:#E68922; padding-bottom:4px;">注册</div></div>
            <form id="my_form" name="my_form" method="post" action="<?=site_url(array('home','regist'));?>">
              <ul class="service">
                  <li class="posclear">
                      <div class="registw1 posfloatl">用户名:</div><input type="text" name="regist_username" id="regist_username" />
                      *<span class="red" id="username_tag">请输入用户名</span>
                  </li>
                   <li><div class="registw1 posfloatl">邮箱:</div><input type="text" name="regist_email" id="regist_email" />*<span class="red" id="email_tag">请输入邮箱</span></li>
                  <li class="posclear">
                      <div class="registw1 posfloatl">密码:</div><input type="password" name="regist_password" id="regist_password" />
                      *<span class="red" id="password_tag">请输入密码</span>
                  </li>
                  <li>
                      <div class="registw1 posfloatl">确认密码:</div><input type="password" name="regist_confirm_pwd" id="regist_confirm_pwd" />
                      *<span class="red" id="confirm_pwd_tag">请输入确认密码</span>
                  </li>           
                   <li style="padding:10px 0;">
                      <input style="vertical-align:middle;" type="checkbox" id="server" checked="checked"/>我已阅读并同意<a href="<?=site_url(array('home','server_text'));?>" target="_blank">服务条款</a>
                  </li>
                  <li><input id="submit_button" type="button" value="提交" />&nbsp;&nbsp;<span id="regist_info"></span></li>
              </ul>
            </form>
          </div>
        </div>
    </div>
    </div>
</body>
</html>